package collection.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;

public class StreamDemo2 {
    public static void main(String[] args) {
        Random rand = new Random();
        List<Integer> list = new ArrayList<>();
        for (int i = 0;i<10;i++){
            list.add(rand.nextInt(100));

        }
        System.out.println(list);
        //取流中的最小值
        Optional<Integer> min = list.stream().min((e1,e2)->e1-e2);
        System.out.println(min.get());

        //取流中的最大值
        Optional<Integer> max = list.stream().max((e1,e2)->e1-e2);
        System.out.println(max.get());

        //判断集合中是否包含偶数
        Boolean anyMatch = list.stream().anyMatch(e->e%2==0);
        System.out.println(anyMatch);

        //判断集合中所有元素是否都是偶数
        Boolean allMatch = list.stream().allMatch(e->e%2==0);
        System.out.println(allMatch);

        //判断集合中是否没有偶数
        Boolean noneMatch = list.stream().noneMatch(e->e%2==0);
        System.out.println(noneMatch);

        //对所有集合元素求和
        int num = list.stream().reduce((e1,e2)->e1+e2).get();
        System.out.println(num);


































    }
}
